<template>
  <div class="add-node-btn-box">
    <div class="add-node-btn">
      <el-popover v-model="visible" placement="right-start">
        <div class="add-node-popover-body">
          <a class="add-node-popover-item approver" @click="addType(1)">
            <div class="item-wrapper">
              <i class="iconfont icon-shenpi" />
            </div>
            <p>审批人</p>
          </a>
          <a class="add-node-popover-item notifier" @click="addType(2)">
            <div class="item-wrapper">
              <span class="iconfont icon-chaosong" />
            </div>
            <p>抄送人</p>
          </a>
          <a class="add-node-popover-item condition" @click="addType(4)">
            <div class="item-wrapper">
              <span class="iconfont icon-liucheng1" />
            </div>
            <p>添加条件</p>
          </a>
          <!--          <a class="add-node-popover-item condition" @click="addType(10)">-->
          <!--            <div class="item-wrapper" style="transform: rotate(180deg);">-->
          <!--              <span class="iconfont icon-liucheng1" />-->
          <!--            </div>-->
          <!--            <p>并行任务</p>-->
          <!--          </a>-->
        </div>
        <button slot="reference" class="btn" type="button">
          <i class=" el-icon-plus" />
        </button>
      </el-popover>
    </div>
  </div>
</template>
<script>
import {uuid} from "@/utils"

export default {
  props: ["nextNodeP"],
  data() {
    return {
      visible: false
    }
  },
  methods: {
    addType(type) {
      let id = uuid()
      this.visible = false
      if (type != 4) {
        let data
        if (type == 1) {
          data = {
            "nodeName": "审核人",
            "jobType": "user-" + id,
            "type": 1,
            "nodeUserList": [],
            "nodeRoleList": [],
            "nodePostList": [],
            "taskEvents": {
              agree: false,
              agreeNotifyUrl: '',
              reject: false,
              rejectNotifyUrl: ''
            },
            "nodeType": "userTask",
            "nextNode": this.nextNodeP
          }
        } else if (type == 2) {
          data = {
            "id": "copyer-" + id,
            "nodeName": "抄送人",
            "nodeType": "serviceTask",
            "type": 2,
            "bizType": "1",
            "nodeUserList": [],
            "nextNode": this.nextNodeP
          }
        } else {
          data = {
            "nodeName": "",
            "type": 10,
            "id": "parallel-" + id,
            "nodeType": "parallelGateway",
            "branchNodes": [{
              "nodeName": "条件1",
              "type": 7,
              "conditionList": [],
              "nextNode": this.nextNodeP
            }, {
              "nodeName": "分支2",
              "type": 7,
              "conditionList": [],
              "nextNode": null
            }],
            "nextNode": {
              "nodeName": "",
              "type": -1,
              "nodeType": "parallelGateway",
              "nextNode": this.nextNodeP
            }
          }
        }
        this.$emit("update:nextNodeP", data)
      } else {
        this.$emit("update:nextNodeP", {
          "nodeName": "",
          "type": 4,
          "nodeType": "exclusiveGateway",
          "nextNode": this.nextNodeP,
          "branchNodes": [{
            "nodeName": "条件1",
            "type": 7,
            "conditionList": [], // 条件表达式
            "nextNode": null
          }, {
            "nodeName": "条件2",
            "type": 7,
            "conditionList": [],
            "nextNode": null
          }]
        })
      }
    }
  }
}
</script>
